<?php
// 应用公共文件


if (!function_exists('dump')) {
    /**
     * 浏览器友好的变量输出
     * @param mixed $vars 要输出的变量
     * @return void
     */
    function dump(...$vars)
    {
        ob_start();
        var_dump(...$vars);

        $output = ob_get_clean();
        $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output);

        if (PHP_SAPI == 'cli') {
            $output = PHP_EOL . $output . PHP_EOL;
        } else {
            if (!extension_loaded('xdebug')) {
                $output = htmlspecialchars($output, ENT_SUBSTITUTE);
            }
            $output = '<pre>' . $output . '</pre>';
        }

        echo $output;
    }
}

if (!function_exists('halt')) {
    /**
     * 调试变量并且中断输出
     * @param mixed $vars 调试变量或者信息
     */
    function halt(...$vars)
    {
        dump(...$vars);

        exit();
    }
}



function config($name){
    list($file , $field) = explode("." , $name);
    $file = ROOT . 'config/' .$file . '.php';
    if (!empty($GLOBALS['base_config'][$file])){
        $config = $GLOBALS['base_config'][$file];
    } else {
        if (file_exists($file)) {
            $config = include $file;

            $GLOBALS['base_config'][$file] = $config;

        } else {
            return [];
        }
    }
    if (!empty($field))
        return $config[$field] ?? '';

    return $config;

}